local ClientOHOH = _G.ClientOHOH;
local M = ClientOHOH.class.new(script, ClientOHOH.files.ModelObject());
local CallBackManager = ClientOHOH.load.CallBackManager();
local BigNumberHelper = ClientOHOH.load.BigNumberHelper();
local PlayerInfoHelper=_G.ClientOHOH.load.PlayerInfoHelper()
local LanguageHelper=_G.LanguageHelper 
local TweenHelper = ClientOHOH.load.TweenHelper();

local ConnectClass=_G.CommonOHOH.load.Connect();

function M.new(...)
	return M(...);
end;

function M.ctor(self,model,title,fullFuc)--构造函数
	assert(model,"model==nul")
	M.super.ctor(self, model);
	self.TitleTip=ClientOHOH:GetPath_Loop("ui.ui.ui.TextLabel",model)
    self.TitleTip.Visible=false
    self.TitleTip.Text=LanguageHelper:GetText(30025)
    self.NullTip=ClientOHOH:GetPath_Loop("ui.SurfaceGui.Frame.con",model)
    self.NullTip.Text=LanguageHelper:GetText(30028)
    self.Cell=ClientOHOH:GetPath_Loop("ui.SurfaceGui.Frame.ScrollingFrame.cell",model)
    ClientOHOH:GetPath_Loop("ui.SurfaceGui.Frame.title",model).Text=LanguageHelper:GetText(30025)
    ClientOHOH:GetPath_Loop("btn.receive",self.Cell).Text=LanguageHelper:GetText(10403)
    self.TipMesh=ClientOHOH:GetPath_Loop("remind",model)
    self.Aniamtor=ClientOHOH:GetPath_Loop("remind.Animator",model)

    self:CloseTip()
    self.ClaimEvent=ConnectClass.new()
    self.OldTipPos= self.TipMesh.Position

    self.TipMesh.Position= self.OldTipPos
    self.Tween=TweenHelper:PlayTween(self.TipMesh, TweenInfo.new(0.5, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut,-1,true), {
		Position =self.OldTipPos+Vector3.new(0,-3,3) --关闭状态位置
	});

    self.CellList={}
end;

function M.CloseTip(self)
    self.TipMesh.Transparency=1
    self.NullTip.Visible=true

    

    -- if self.PlayLoopConnect then
    --     self.PlayLoopConnect:Disconnect()
    --     self.PlayLoopConnect=nil
    -- end

    -- 30028\

    -- require(self.Aniamtor).NewTween:Stop()
    -- self.TitleTip.Visible=false
end

function M.ShowTip(self,data)
    self.TipMesh.Transparency=0
    -- require(self.Aniamtor).NewTween:Loop()
    -- self.PlayLoopConnect=self:AddProcess(function()
    --     while true do
    --         require(self.Aniamtor).NewTween:Loop()
    --         self:Wait(3)
    --     end
    -- end)


    self.NullTip.Visible=false
    -- self.TitleTip.Visible=true
end


function M.CreateCellObj(self,userId,level,count)-- 更新数据
    local c= self.Cell:Clone()
    c.Parent=self.Cell.Parent
    c.Visible=true
    ClientOHOH:GetPath_Loop("Icon.Username",c).Text=userId
    PlayerInfoHelper.GetPlayerInfo(userId,function(headImage,name)
       
        if c and c.Icon then
            c.Icon.Image=headImage
            c.Icon.Username.Text=name
        end
        -- ClientOHOH:GetPath_Loop("Icon",c).Image=headImage
        -- ClientOHOH:GetPath_Loop("Icon.Username",c).Text=name
    end)

    ClientOHOH:GetPath_Loop("Leve",c).Text=LanguageHelper:GetText(30024,{"%%ARG1"},{level})
    ClientOHOH:GetPath_Loop("num.num",c).Text=BigNumberHelper:ToString(count)


    CallBackManager:AddRbxConnect(self,ClientOHOH:GetPath_Loop("btn",c).Activated, function()
        if self.Clicking then
            return
        end
        self.Clicking=true
        local s=self.ClaimEvent:Action(level,userId,#self.CellList-1)
        if s then
            for k,v in pairs(self.CellList) do
                if v==c then
                    table.remove(self.CellList,k)
                    break
                end
            end
            c:Destroy()
        end

        if #self.CellList<=0 then
            self:CloseTip()
        end
        self.Clicking=nil

	end);

    table.insert(self.CellList,c)

end

function M.Update(self,data)-- 更新数据

    self.Clicking=nil
    for _,c in pairs(self.CellList) do
        c:Destroy()
    end

    self.CellList={}
    
	for _,v in pairs(data) do
        self:CreateCellObj(v.uid,v.level,v.count)
	end

    if #self.CellList>0 then
        self:ShowTip()
    end
end;

function M.dtor(self)--析构函数
	M.super.dtor(self);
end;

return M